package com.inray.nbs.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.inray.nbs.bean.Fleet;
import com.inray.nbs.bean.Userinfo;
import com.inray.nbs.bean.Vehicle_info;
import com.inray.nbs.bean.Vehicle_type;
import com.inray.nbs.bean.Vehicle_warning_data;
import com.inray.nbs.dao.BaseDao;
import com.inray.nbs.service.FleetService;

@Service
public class FleetServiceImpl implements FleetService{
	@Resource(name="baseDaoImpl")
	protected BaseDao baseDao;
	
	@Override
	public List<Fleet> selectFleetData(Map<String,Object> map){
		return baseDao.selectListBySqlId("Fleet.selectFleetData", map);
	}
	@Override
	public List<Fleet> selectFleetAll() {
		// TODO Auto-generated method stub
		return baseDao.selectListBySqlId("Fleet.selectFleetAll",null);
	}
	
	@Override
	public int addFleet(Fleet fleet) {
		return baseDao.insert(fleet);
	}

	@Override
	public int editFleet(Fleet fleet) {
		return baseDao.update(fleet);
	}

	@Override
	public int delFleet(Fleet fleet) {
		return baseDao.delete(Fleet.class, fleet.getFleetid());
	}
	
	@Override
	public List<Vehicle_type> selectVehicleTypeData(Map<String,Object> map){
		return baseDao.selectListBySqlId("Vehicle_type.selectVehicleTypeData", map);
	}
	@Override
	public List<Vehicle_info> selectVehicleData(Map<String,Object> map){
		return baseDao.selectListBySqlId("Vehicle_info.selectVehicleData", map);
	}
	public List<Vehicle_info> selectVehicleById(Map<String,Object> map){
		return baseDao.selectListBySqlId("Vehicle_info.selectVehicleById", map);
	}
	@Override
	public List<Vehicle_info> selectOldVehicleData(Map<String,Object> map){
		return baseDao.selectListBySqlId("Vehicle_info.selectOldVehicleData", map);
	}
	@Override
	public int ImportVehicle(List<Vehicle_info> lst){
		int i=1;
		for(Vehicle_info in:lst){
			i=baseDao.insert(in);
		}
		return i;
	}
	@Override
	public int ImportVehicle(Vehicle_info lst){
		return baseDao.insert(lst);
	}
	@Override
	public int ImportVehicleEdit(Vehicle_info lst){
		return baseDao.updateBySqlId("Vehicle_info.ImportVehicleEdit", lst);
	}
	@Override
	public int addVehicleType(Vehicle_type fleet) {
		return baseDao.insert(fleet);
	}

	@Override
	public int editVehicleType(Vehicle_type fleet) {
		return baseDao.update(fleet);
	}

	@Override
	public int delVehicleType(Vehicle_type fleet) {
		return baseDao.delete(Vehicle_type.class, fleet.getId());
	}

	@Override
	public int addVehicle(Vehicle_info fleet) {
		if(fleet.getFleetid()!=null){
			if(fleet.getFleetid()==0){
				fleet.setFleetid(null);
			}
		}
		if(fleet.getTypeid()!=null){
			if(fleet.getTypeid()==0){
				fleet.setTypeid(null);
			}
		}
		return baseDao.insert(fleet);
	}

	@Override
	public int editVehicle(Vehicle_info fleet) {
		if(fleet.getFleetid()!=null){
			if(fleet.getFleetid()==0){
				fleet.setFleetid(null);
			}
		}
		if(fleet.getTypeid()!=null){
			if(fleet.getTypeid()==0){
				fleet.setTypeid(null);
			}
		}
		return baseDao.update(fleet);
	}

	@Override
	public int delVehicle(Vehicle_info fleet) {
		return baseDao.delete(Vehicle_info.class, fleet.getVehicleid());
	}
	@Override
	public int romveVehicleFleet(Integer fleetid){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("fleetid", fleetid);
		return baseDao.updateBySqlId("Vehicle_info.romveVehicleFleet", map);
	}
	@Override
	public int SaveVehicleDis(Map<String,Object> map){
		return baseDao.updateBySqlId("Vehicle_info.SaveVehicleDis", map);
	}
	@Override
	public Userinfo selectUserByOne(Integer userid){
		return (Userinfo) baseDao.selectOneById(Userinfo.class, userid);
	}
	@Override
	public List<Vehicle_warning_data> selectVehicleAlertData(Map<String,Object> map){
		return baseDao.selectListBySqlId("Vehicle_info.selectVehicleAlertData", map);
	}

	@Override
	public List<Vehicle_info> selectVehicleFleet(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return baseDao.selectListBySqlId("Vehicle_info.selectVehicleFleet", map);
	}
}
